using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Runtime.Serialization;

namespace Cephei.Core
{
    /// <summary>
    /// method by which a cells value changes
    /// </summary>
    [DataContract (Name = "CellMethod", Namespace = Declarations.SchemaVersion)]
    [Serializable]
    public enum CellMethod
    {
        [EnumMember]
        Unknown,                    // initial value.. before calculator or value assigned
        [EnumMember]
        OnDemand,                   // calculate whenever needed
        [EnumMember]
        InThread,                   // calculate in the threadpool
        [EnumMember]
        OnDemandOrInLine,           // last calculation was quicker than scheduling, so decide onDemand or InLine next time
        [EnumMember]
        InLine,                     // calculate whenever a dependancy changes
        [EnumMember]
        InGrid,                     // calculate by dispatch to a grid !! not implemented
        [EnumMember]
        ByAssignment                // not calculated, but assigned
    };

    /// <summary>
    /// Event generated by a cell to notify dependants about changes
    /// </summary>
    [Serializable]
    [DataContract (Name = "CellEventType", Namespace = Declarations.SchemaVersion)]
    public enum CellEventType
    {
        [EnumMember]
        Create = 0,					// default is that it was simply created
        [EnumMember]
        CircularReferenceCheck,		// Check for Circular references
        [EnumMember]
        Invalidate,					// Invaidate message is sent by threaded calcualtions to invalidate objects without causing a cascade of blocked threads
        [EnumMember]
        Calculate,					// do the calculation if needed 
        [EnumMember]
        ErrorAbort,					// an error occured in the calcualtion.. all dependant changes should be abandoned
        [EnumMember]
        Link,                       // when the value of a cell changes in the model, force ICalculators to switch references
        [EnumMember]
        Change,						// notify parent object that this value has changed
        [EnumMember]
        SimulationComplete,         // Sent by a scenario cells to signal other scenario or Outcome objects that it has completed
        [EnumMember]
        Delete                      // The item has been removed from a model, and any causual observes should unlink
    }

    /// <summary>
    /// Event generated by an event consumer for providers
    /// </summary>
    [Serializable]
    [DataContract (Name = "CellSinkEventType", Namespace = Declarations.SchemaVersion)]
    public enum CellSinkEventType
    {
        [EnumMember]
        SimulationReset,            // Sent by a Scenario Outcome object to reset Scenarios
        [EnumMember]
        TriggerSpan,                // Notify sources about the minimum timespan that a consumer can cope with changes
        [EnumMember]
        DemandSpan,                 // Notfiy the span by which the calcualtion must be finished
        [EnumMember]
        BeginRealtime,              // Notify sources that events are contributing to real time feeds
        [EnumMember]
        EndRealtime,                // hint to sources realtime contribution has stopped
        [EnumMember]
        BeginView,                  // Notify sources that events are being viewed
        [EnumMember]
        EndView,                    // View has stoppped
        [EnumMember]
        Delete                      // The cell has been removed from the model, any causual observers should be removed

    }

    [Serializable]
    [DataContract (Name = "CellState", Namespace = Declarations.SchemaVersion)]
    public enum CellState
    {
        [EnumMember]
        IsUnknown = 0,				// To allow for forward declaration, to be determined later
        [EnumMember]
        IsValue = 1,                // is a value
        [EnumMember]
        IsClean = 2,                // is calculated and has a clean value
        [EnumMember]
        IsDirty = 4,                // is calculated, but the value is invalid
        [EnumMember]
        IsHollow = 32 + 4,          // has a formula but never calculated 
        [EnumMember]
        IsCollection = 8,           // is a value collection
        [EnumMember]
        IsError = 16,               // is normally calculated, but the last caculation produced an error
    };
}
    